package com.itjiange.getway.config;

import com.itjiange.getway.common.IpKeyResolver;
import org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * 限流配置
 * @author ItJianGe
 * @data 2024/4/9 18:13
 */
@Configuration
public class RateLimitConfig {
    @Bean
    public KeyResolver apiKeyResolver() {
        // 按照 URL 限流
        return exchange -> Mono.just(exchange.getRequest().getPath().toString());
    }
}
